package com.shiliao.app.activity.index.adapter;


import android.content.Context;
import android.view.View;

import com.shiliao.app.R;
import com.shiliao.app.activity.index.entity.WaitExamineEntity;
import com.yimei.framework.ui.recyclerview.CommonAdapter;
import com.yimei.framework.ui.recyclerview.base.ViewHolder;
import com.yimei.framework.util.LogUtil;

import java.util.List;

/**
 * Created by yinzhiqiang on 2018/5/21.
 */

public class ExamineAdapter extends CommonAdapter<WaitExamineEntity> {
    private CheckQuestion checkQuestion;
    private int checkId = -1;

    public ExamineAdapter(Context context, int layoutId, List<WaitExamineEntity> datas, CheckQuestion checkQuestion) {
        super(context, layoutId, datas);
        this.checkQuestion = checkQuestion;
    }

    @Override
    protected void convert(final ViewHolder holder, WaitExamineEntity waitExamineEntity, final int position) {
        holder.setText(R.id.tv_content_examine, waitExamineEntity.examinResult.toString());

        holder.setImageResource(R.id.iv_choice, R.drawable.ic_mall_agreement_unselected);
        if (checkId == position && checkId != -1) {
            holder.setImageResource(R.id.iv_choice, R.drawable.ic_mall_agreement_unselected);
        }
        holder.setOnClickListener(R.id.ll_item_click, v -> {
            LogUtil.e("yzq", checkId + "==" + position);
            if (checkId != position) {
                LogUtil.e("yzq", checkId + "==" + position);
                holder.setImageResource(R.id.iv_choice, R.drawable.ic_mall_agreement_selected);
                notifyItemChanged(checkId);
                checkId = position;
            }
            checkQuestion.clickCheck(waitExamineEntity.examinId);
        });

    }

    public interface CheckQuestion {
        void clickCheck(String position);
    }
}
